//
//  JYPublicCell.m
//  JYFarm
//
//  Created by 花花 on 2017/10/20.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYPublicCell.h"
#import "JYFontColorTool.h"
#import "ShoppingCartTool.h"
@implementation JYPublicCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.minBtn.layer.borderWidth =1.0;
    self.minBtn.layer.borderColor = [UIColor colorWithHexString:@"62C6B2"].CGColor;
    self.minBtn.layer.cornerRadius = self.minBtn.frame.size.width * 0.5;
    
    
    
    self.maxBtn.layer.borderWidth =1.0;
    self.maxBtn.layer.borderColor = [UIColor colorWithHexString:@"62C6B2"].CGColor;
    self.maxBtn.layer.cornerRadius = self.maxBtn.frame.size.width * 0.5;
    self.maxBtn.layer.masksToBounds = YES;
    
    
    self.bordView.layer.borderWidth = 1;
    self.bordView.layer.borderColor = [UIColor colorWithHexString:@"F2F2F2"].CGColor;
    
}


- (IBAction)starsBtnOnClick:(UIButton *)sender {
    
    
    sender.selected = !sender.selected;
    if (self.selectStarsBtnClick) {
        self.selectStarsBtnClick(sender.selected);
    }
    
    
}
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index {
    [super insertSubview:view atIndex:index];
    
    if ([view isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
        view.top = 10;
        view.height = self.height - 10;
        
        for (UIButton *btn in view.subviews) {
            
            if ([btn isKindOfClass:[UIButton class]]) {
                
                [btn setBackgroundColor:kf2Color];
                
                [btn setTitle:nil forState:UIControlStateNormal];
                
                [btn setImage:[UIImage imageNamed:@"list_deleting"] forState:UIControlStateNormal];
                
                [btn setTintColor:[UIColor whiteColor]];
            }
        }
    }
}


/*
 
 categroyId = 2;
 createTime = "<null>";
 deletCommonUserOrderType = 0;
 depositObj = "<null>";
 goodsAmount = 1;
 goodsDesc = "<null>";
 goodsId = 7;
 goodsName = "\U5f20\U88d5\U4e8c\U53f7";
 goodsPictureUrl = "http://pic.jinyoufarm.com/72df0411.jpg";
 goodsPrice = "1.2";
 list = "<null>";
 operateType = 0;
 originalprice = 20;
 unit = "\U4e2a";
 userId = "8f42310f-0bfc-4b79-a6f9-52b0b0adc384";
 */

- (void)setListModel:(JYListModel *)listModel{


    _listModel = listModel;
    self.nameLabel.text = listModel.goodsName;
    
    
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f",[listModel.goodsPrice doubleValue]];
    
    self.starsBtn.hidden = YES;
    self.unitLabel.text  = listModel.unit;
    
    self.count.text = [NSString stringWithFormat:@"%zd", listModel.goodsAmount];
    self.oldPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[listModel.originalprice doubleValue]];
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:listModel.goodsPictureUrl] placeholderImage:defaultFarmImage];
    

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

/**
 
 cell.nameLabel.text = model.name;
 cell.unitLabel.text = model.spec;
 cell.count.text = [NSString stringWithFormat:@"%ld",model.amount];
 [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:defaultFarmImage];
 cell.priceLabel.text = model.price;
 NSString *originalPrice = nil;
 if (model.originalPrice == nil) {
 originalPrice= [NSString stringWithFormat:@"%.2f",[model.originalPrice doubleValue]];
 }else{
 originalPrice = model.originalPrice;
 }
 cell.oldPriceLabel.text = originalPrice;
 
 */

- (void)setHomeModel:(BaseModel *)homeModel{

    _homeModel = homeModel;
    
    self.nameLabel.text = homeModel.name;
//    self.priceLabel.text = homeModel.originalPrice;
//
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f",[homeModel.price doubleValue]];
    
    self.unitLabel.text  = [NSString stringWithFormat:@"/%@",homeModel.spec];
    self.oldPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[homeModel.originalPrice doubleValue]];
    
    
    self.count.text = [NSString stringWithFormat:@"%zd",homeModel.amount];

    [self.imgView sd_setImageWithURL:[NSURL URLWithString:homeModel.image] placeholderImage:defaultFarmImage];
    
    self.starsBtn.selected = homeModel.collect;
    
//    if (homeModel.collect == 1) {
//        self.starsBtn.selected = YES;
//    }else{
//        self.starsBtn.selected = NO;
//    }
    
    
}


- (IBAction)addOnClick:(UIButton *)sender {
  
    
    NSInteger count = self.count.text.integerValue;
    if (self.ShopCountEditBlock) {
        self.ShopCountEditBlock(++count,_imgView);
    }
    
    
    
      
    
}
- (IBAction)minOnClick {
    
    
    NSInteger count = self.count.text.integerValue;
    if (self.ShopCountEditBlock) {
        self.ShopCountEditBlock(--count,_imgView);
    }
}


@end
